﻿using System;
using System.Reflection;
using JUtil.Extensions;

class ConnectionStringBuilder
{
    public ConnectionStringBuilder(string connectionString)
    {
        string[] tokens = connectionString.SplitString(";");

        Type type = GetType();
        FieldInfo[] fis = type.GetFields();

        foreach (string token in tokens)
        {
            foreach (FieldInfo fi in fis)
            {
                string fiName = fi.Name;
                string fiValue = string.Empty;

                int pos = token.IndexOf(fiName);

                if (pos != -1)
                {
                    pos = pos + fiName.Length + 1;

                    fiValue = token.Substring(pos);

                    fi.SetValue(this, fiValue);

                    break;
                }
            }
        }
    }
}